/*
*求数据的交并差，C++，vs2010编译
*/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;
int readNumbers(std::vector<int> &);
void ifSuccess(int );
void _sort(std::vector<int> &);
void printVec(std::vector<int> const &);
std::vector<int> jiao(std::vector<int> const &,std::vector<int> const &);
std::vector<int> bing(std::vector<int> const &,std::vector<int> const &);
std::vector<int> cha(std::vector<int> const &,std::vector<int> const &);

int main()
{
	std::vector<int> A,B;
	cout << "please input some number,-1 to the end; A:" << endl;
	ifSuccess(readNumbers(A));
	_sort(A);
	cout << "please input some number,-1 to the end; B:" << endl;
	ifSuccess(readNumbers(B));
	_sort(B);
	cout << "------------\n";
	cout << "A   :";
	printVec(A);
	cout << "B   :";
	printVec(B);
	cout << "jiao:";
	printVec(jiao(A,B));
	cout << "bing:";
	printVec(bing(A,B));
	cout << "cha :";
	printVec(cha(A,B));
	cout << "------------\n";
	return 0;
}

int readNumbers(std::vector<int> &numbers)
{
	int x;
	while(cin >> x && x != -1){
		numbers.push_back(x);
	}
	return 0;
}

void ifSuccess(int status)
{
	if(status == 0){
		cout << "Success" << endl;
	}else{
		cout << "failed" << endl;
		exit(1);
	}
}

void _sort(std::vector<int> &numbers)
{
	int tmp;
	for(vector<int>::iterator i = numbers.begin();i < numbers.end();i ++){
		for(vector<int>::iterator j = i + 1;j < numbers.end();){
			if(*i == *j){
				numbers.erase(j);
			}else if(*i > *j){
				tmp = *i;
				*i = *j;
				*j = tmp;
			}else{
				j ++;
			}
		}
	}
}

void printVec(std::vector<int> const &numbers)
{
	for(int i = 0;i < numbers.size();i ++)
		cout << numbers[i] << " ";
	cout << endl;
}

std::vector<int> jiao(std::vector<int> const &A,std::vector<int> const &B)
{
	std::vector<int> C;
	for(int i = 0;i < A.size();i ++){
		for(int j = 0;j < B.size();j ++){
				if(A[i] == B[j]){
					C.push_back(A[i]);
					break;
				}
		}
	}
	return C;
}

std::vector<int> bing(std::vector<int> const &A,std::vector<int> const &B)
{
	std::vector<int> C;
	int minLength = A.size() < B.size() ?A.size():B.size();
	int p = 0,q = 0,j = 0;
	for(int i = 0;;i ++){
		if(p < minLength && q < minLength){
			if(A[p] < B[q]){
				C.push_back(A[p]);
				p ++;
			}else if(A[p] > B[q]){
				C.push_back(B[q]);
				q ++;
			}else{
				C.push_back(A[p]);
				p ++;
				q ++;
			}
		}else{
			
			if(p == A.size()) j = 1;
			if(q == B.size()) j = 2;
			if(j == 1 && q < B.size()){
				C.push_back(B[q]);
				q ++;
			}else if(j == 2 && p <A.size()){
				C.push_back(A[p]);
				p ++;
			}else{
				break;
			}
			
		}
	}
	return C;
}

std::vector<int> cha(std::vector<int> const &A,std::vector<int> const &B)
{
	std::vector<int> C;
	int p = 0,q = 0;
	for(int i = 0;i < A.size();i ++){
			if(A[p] == B[q]){
				p ++;
				q ++;
			}else if(A[p] < B[q]){
				C.push_back(A[p]);
				p ++;
			}else if(A[p] > B[q]){
				q ++;
			}
		}
	return C;
}